using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Configuration;
using System.Runtime.InteropServices;

using PCSComUtils.DataAccess;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;

namespace PCSComMaterials.Inventory.DS
{
	public enum MaterialIssueType
	{
		SO_Issue = 0,
		WO_Issue = 1
	}

	public class IV_MaterialIssueDS
	{
		private const string THIS = "PCSComMaterials.Inventory.DS.IV_MaterialIssueDS";

		public IV_MaterialIssueDS()
		{
		}
	
		///    <summary>
		///       This method uses to add data to IV_MaterialIssue
		///    </summary>
		///    <Inputs>
		///        IV_MaterialIssueVO
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>


		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;

			try
			{
				IV_MaterialIssueVO objObject = (IV_MaterialIssueVO) pobjObjectVO;				
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				
				string strSql = "INSERT INTO " + IV_MaterialIssueTable.TABLE_NAME + "("				
				+ IV_MaterialIssueTable.MASTERLOCATIONID_FLD + ","
				+ IV_MaterialIssueTable.POSTDATE_FLD + ","
				+ IV_MaterialIssueTable.BINID_FLD + ","
				+ IV_MaterialIssueTable.LOCATIONID_FLD + ","
				+ IV_MaterialIssueTable.CCNID_FLD + ","
				+ IV_MaterialIssueTable.TRANSNO_FLD + ","
				+ IV_MaterialIssueTable.COMMENT_FLD + ","
				+ IV_MaterialIssueTable.PRODUCTID_FLD + ","
				+ IV_MaterialIssueTable.STOCKUMID_FLD + ","
				+ IV_MaterialIssueTable.LOT_FLD + ","
				+ IV_MaterialIssueTable.SERIAL_FLD + ","
				+ IV_MaterialIssueTable.QASTATUS_FLD + ","
				+ IV_MaterialIssueTable.ISSUETYPE_FLD + ","
				+ IV_MaterialIssueTable.ISSUEQUANTITY_FLD + ","
				+ IV_MaterialIssueTable.WORKORDERMASTERID_FLD + ","
				+ IV_MaterialIssueTable.WORKORDERDETAILID_FLD + ","
				+ IV_MaterialIssueTable.SALEORDERMASTERID_FLD + ","
				+ IV_MaterialIssueTable.SALEORDERDETAILID_FLD + ")"
				+ " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
				
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				
				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.MASTERLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.MASTERLOCATIONID_FLD].Value = objObject.MasterLocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.POSTDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[IV_MaterialIssueTable.POSTDATE_FLD].Value = objObject.PostDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.BINID_FLD, OleDbType.Integer));
				if(objObject.BinID == 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.BINID_FLD].Value = DBNull.Value;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.BINID_FLD].Value = objObject.BinID;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.LOCATIONID_FLD, OleDbType.Integer));
				if(objObject.LocationID == 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.LOCATIONID_FLD].Value = DBNull.Value;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.LOCATIONID_FLD].Value = objObject.LocationID;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.CCNID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.CCNID_FLD].Value = objObject.CCNID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.TRANSNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.TRANSNO_FLD].Value = objObject.TransNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.COMMENT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.COMMENT_FLD].Value = objObject.Comment;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.STOCKUMID_FLD, OleDbType.Integer));
				if(objObject.UMID >0) 
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.STOCKUMID_FLD].Value = objObject.UMID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.STOCKUMID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.LOT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.LOT_FLD].Value = objObject.Lot;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SERIAL_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.SERIAL_FLD].Value = objObject.Serial;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.QASTATUS_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.QASTATUS_FLD].Value = objObject.QAStatus;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.ISSUETYPE_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.ISSUETYPE_FLD].Value = objObject.IssueType;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.ISSUEQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_MaterialIssueTable.ISSUEQUANTITY_FLD].Value = objObject.IssueQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.WORKORDERMASTERID_FLD, OleDbType.Integer));
				if(objObject.WorkOrderMasterID > 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERMASTERID_FLD].Value = objObject.WorkOrderMasterID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERMASTERID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.WORKORDERDETAILID_FLD, OleDbType.Integer));
				if(objObject.WorkOrderDetailID > 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERDETAILID_FLD].Value = objObject.WorkOrderDetailID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERDETAILID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SALEORDERMASTERID_FLD, OleDbType.Integer));
				if(objObject.SaleOrderMasterID > 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERMASTERID_FLD].Value = objObject.SaleOrderMasterID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERMASTERID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SALEORDERDETAILID_FLD, OleDbType.Integer));
				if(objObject.SaleOrderDetailID >0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERDETAILID_FLD].Value = objObject.SaleOrderDetailID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERDETAILID_FLD].Value = DBNull.Value;
				}
								
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch(Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally
			{
				if (oconPCS != null) 
				{
					if(oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
		
		public int AddAndReturnID(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;

			try
			{
				IV_MaterialIssueVO objObject = (IV_MaterialIssueVO) pobjObjectVO;				
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				
				string strSql = "INSERT INTO " + IV_MaterialIssueTable.TABLE_NAME + "("	
					+ IV_MaterialIssueTable.MASTERLOCATIONID_FLD + ","
					+ IV_MaterialIssueTable.POSTDATE_FLD + ","
					+ IV_MaterialIssueTable.BINID_FLD + ","
					+ IV_MaterialIssueTable.LOCATIONID_FLD + ","
					+ IV_MaterialIssueTable.CCNID_FLD + ","
					+ IV_MaterialIssueTable.TRANSNO_FLD + ","
					+ IV_MaterialIssueTable.COMMENT_FLD + ","
					+ IV_MaterialIssueTable.PRODUCTID_FLD + ","
					+ IV_MaterialIssueTable.STOCKUMID_FLD + ","
					+ IV_MaterialIssueTable.LOT_FLD + ","
					+ IV_MaterialIssueTable.SERIAL_FLD + ","
					+ IV_MaterialIssueTable.QASTATUS_FLD + ","
					+ IV_MaterialIssueTable.ISSUETYPE_FLD + ","
					+ IV_MaterialIssueTable.ISSUEQUANTITY_FLD + ","
					+ IV_MaterialIssueTable.WORKORDERMASTERID_FLD + ","
					+ IV_MaterialIssueTable.WORKORDERDETAILID_FLD + ","
					+ IV_MaterialIssueTable.SALEORDERMASTERID_FLD + ","
					+ IV_MaterialIssueTable.SALEORDERDETAILID_FLD + ")"
					+ " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
					+ "; SELECT @@IDENTITY as CreatedID";
				
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				
				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.MASTERLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.MASTERLOCATIONID_FLD].Value = objObject.MasterLocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.POSTDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[IV_MaterialIssueTable.POSTDATE_FLD].Value = objObject.PostDate;
				
				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.BINID_FLD, OleDbType.Integer));
				if(objObject.BinID == 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.BINID_FLD].Value = DBNull.Value;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.BINID_FLD].Value = objObject.BinID;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.LOCATIONID_FLD, OleDbType.Integer));
				if(objObject.LocationID == 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.LOCATIONID_FLD].Value = DBNull.Value;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.LOCATIONID_FLD].Value = objObject.LocationID;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.CCNID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.CCNID_FLD].Value = objObject.CCNID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.TRANSNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.TRANSNO_FLD].Value = objObject.TransNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.COMMENT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.COMMENT_FLD].Value = objObject.Comment;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.STOCKUMID_FLD, OleDbType.Integer));
				if(objObject.UMID >0) 
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.STOCKUMID_FLD].Value = objObject.UMID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.STOCKUMID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.LOT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.LOT_FLD].Value = objObject.Lot;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SERIAL_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.SERIAL_FLD].Value = objObject.Serial;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.QASTATUS_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.QASTATUS_FLD].Value = objObject.QAStatus;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.ISSUETYPE_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.ISSUETYPE_FLD].Value = objObject.IssueType;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.ISSUEQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_MaterialIssueTable.ISSUEQUANTITY_FLD].Value = objObject.IssueQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.WORKORDERMASTERID_FLD, OleDbType.Integer));
				if(objObject.WorkOrderMasterID > 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERMASTERID_FLD].Value = objObject.WorkOrderMasterID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERMASTERID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.WORKORDERDETAILID_FLD, OleDbType.Integer));
				if(objObject.WorkOrderDetailID > 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERDETAILID_FLD].Value = objObject.WorkOrderDetailID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERDETAILID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SALEORDERMASTERID_FLD, OleDbType.Integer));
				if(objObject.SaleOrderMasterID > 0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERMASTERID_FLD].Value = objObject.SaleOrderMasterID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERMASTERID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SALEORDERDETAILID_FLD, OleDbType.Integer));
				if(objObject.SaleOrderDetailID >0)
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERDETAILID_FLD].Value = objObject.SaleOrderDetailID;
				}
				else
				{
					ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERDETAILID_FLD].Value = DBNull.Value;
				}
								
				ocmdPCS.Connection.Open();

				//insert and return newest ID
				return int.Parse(ocmdPCS.ExecuteScalar().ToString());
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch(Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally
			{
				if (oconPCS != null) 
				{
					if(oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		///    <summary>
		///       This method uses to add data to IV_MaterialIssue
		///    </summary>
		///    <Inputs>
		///        IV_MaterialIssueVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = "DELETE " + IV_MaterialIssueTable.TABLE_NAME + " WHERE  " + "MasterLocationID" + "=" + pintID.ToString();
			
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}	

		///    <summary>
		///       This method uses to add data to IV_MaterialIssue
		///    </summary>
		///    <Inputs>
		///        IV_MaterialIssueVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;

			try
			{
				string strSql = "SELECT "
				+ IV_MaterialIssueTable.MASTERLOCATIONID_FLD + ","
				+ IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD + ","
				+ IV_MaterialIssueTable.POSTDATE_FLD + ","
				+ IV_MaterialIssueTable.BINID_FLD + ","
				+ IV_MaterialIssueTable.LOCATIONID_FLD + ","
				+ IV_MaterialIssueTable.CCNID_FLD + ","
				+ IV_MaterialIssueTable.TRANSNO_FLD + ","
				+ IV_MaterialIssueTable.COMMENT_FLD + ","
				+ IV_MaterialIssueTable.PRODUCTID_FLD + ","
				+ IV_MaterialIssueTable.STOCKUMID_FLD + ","
				+ IV_MaterialIssueTable.LOT_FLD + ","
				+ IV_MaterialIssueTable.SERIAL_FLD + ","
				+ IV_MaterialIssueTable.QASTATUS_FLD + ","
				+ IV_MaterialIssueTable.ISSUETYPE_FLD + ","
				+ IV_MaterialIssueTable.ISSUEQUANTITY_FLD + ","
				+ IV_MaterialIssueTable.WORKORDERMASTERID_FLD + ","
				+ IV_MaterialIssueTable.WORKORDERDETAILID_FLD + ","
				+ IV_MaterialIssueTable.SALEORDERMASTERID_FLD + ","
				+ IV_MaterialIssueTable.SALEORDERDETAILID_FLD
				+ " FROM " + IV_MaterialIssueTable.TABLE_NAME
				+ " WHERE " + IV_MaterialIssueTable.MASTERLOCATIONID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				IV_MaterialIssueVO objObject = new IV_MaterialIssueVO();

				while (odrPCS.Read())
				{ 
					objObject.MasterLocationID = int.Parse(odrPCS[IV_MaterialIssueTable.MASTERLOCATIONID_FLD].ToString().Trim());
					objObject.MaterialIssueMasterID = int.Parse(odrPCS[IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD].ToString().Trim());
					objObject.PostDate = DateTime.Parse(odrPCS[IV_MaterialIssueTable.POSTDATE_FLD].ToString().Trim());					
					objObject.LocationID = int.Parse(odrPCS[IV_MaterialIssueTable.LOCATIONID_FLD].ToString().Trim());
					objObject.CCNID = int.Parse(odrPCS[IV_MaterialIssueTable.CCNID_FLD].ToString().Trim());
					objObject.TransNo = odrPCS[IV_MaterialIssueTable.TRANSNO_FLD].ToString().Trim();
					objObject.Comment = odrPCS[IV_MaterialIssueTable.COMMENT_FLD].ToString().Trim();
					objObject.ProductID = int.Parse(odrPCS[IV_MaterialIssueTable.PRODUCTID_FLD].ToString().Trim());
					objObject.UMID = int.Parse(odrPCS[IV_MaterialIssueTable.STOCKUMID_FLD].ToString().Trim());
					objObject.Lot = odrPCS[IV_MaterialIssueTable.LOT_FLD].ToString().Trim();
					objObject.Serial = odrPCS[IV_MaterialIssueTable.SERIAL_FLD].ToString().Trim();
					objObject.QAStatus = odrPCS[IV_MaterialIssueTable.QASTATUS_FLD].ToString().Trim();
					objObject.IssueType = int.Parse(odrPCS[IV_MaterialIssueTable.ISSUETYPE_FLD].ToString().Trim());
					objObject.IssueQuantity = Decimal.Parse(odrPCS[IV_MaterialIssueTable.ISSUEQUANTITY_FLD].ToString().Trim());

					if(!odrPCS[IV_MaterialIssueTable.BINID_FLD].Equals(DBNull.Value)
						&& !odrPCS[IV_MaterialIssueTable.BINID_FLD].ToString().Equals(string.Empty))
					{
						objObject.BinID = int.Parse(odrPCS[IV_MaterialIssueTable.BINID_FLD].ToString().Trim());
					}

					if(objObject.IssueType != (int)MaterialIssueType.SO_Issue)
					{
						objObject.WorkOrderMasterID = int.Parse(odrPCS[IV_MaterialIssueTable.WORKORDERMASTERID_FLD].ToString().Trim());
						objObject.WorkOrderDetailID = int.Parse(odrPCS[IV_MaterialIssueTable.WORKORDERDETAILID_FLD].ToString().Trim());
						objObject.SaleOrderMasterID = 0;
						objObject.SaleOrderDetailID = 0;
					}
					else
					{
						objObject.WorkOrderMasterID = 0;
						objObject.WorkOrderDetailID = 0;
						objObject.SaleOrderMasterID = int.Parse(odrPCS[IV_MaterialIssueTable.SALEORDERMASTERID_FLD].ToString().Trim());
						objObject.SaleOrderDetailID = int.Parse(odrPCS[IV_MaterialIssueTable.SALEORDERDETAILID_FLD].ToString().Trim());
					}
				}

				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
		
		public object GetMaterialIssueByTransNo(string pstrTransNo)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;

			try
			{
				string strSql = "SELECT "
					+ IV_MaterialIssueTable.MASTERLOCATIONID_FLD + ","
					+ IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD + ","
					+ IV_MaterialIssueTable.POSTDATE_FLD + ","
					+ IV_MaterialIssueTable.BINID_FLD + ","
					+ IV_MaterialIssueTable.LOCATIONID_FLD + ","
					+ IV_MaterialIssueTable.CCNID_FLD + ","
					+ IV_MaterialIssueTable.TRANSNO_FLD + ","
					+ IV_MaterialIssueTable.COMMENT_FLD + ","
					+ IV_MaterialIssueTable.PRODUCTID_FLD + ","
					+ IV_MaterialIssueTable.STOCKUMID_FLD + ","
					+ IV_MaterialIssueTable.LOT_FLD + ","
					+ IV_MaterialIssueTable.SERIAL_FLD + ","
					+ IV_MaterialIssueTable.QASTATUS_FLD + ","
					+ IV_MaterialIssueTable.ISSUETYPE_FLD + ","
					+ IV_MaterialIssueTable.ISSUEQUANTITY_FLD + ","
					+ IV_MaterialIssueTable.WORKORDERMASTERID_FLD + ","
					+ IV_MaterialIssueTable.WORKORDERDETAILID_FLD + ","
					+ IV_MaterialIssueTable.SALEORDERMASTERID_FLD + ","
					+ IV_MaterialIssueTable.SALEORDERDETAILID_FLD
					+ " FROM " + IV_MaterialIssueTable.TABLE_NAME
					+ " WHERE " + IV_MaterialIssueTable.TRANSNO_FLD + "='" + pstrTransNo.Replace("'", "''") + "'";

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				IV_MaterialIssueVO objObject = null;

				if(odrPCS.Read())
				{ 
					objObject = new IV_MaterialIssueVO();

					objObject.MasterLocationID = int.Parse(odrPCS[IV_MaterialIssueTable.MASTERLOCATIONID_FLD].ToString().Trim());
					objObject.MaterialIssueMasterID = int.Parse(odrPCS[IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD].ToString().Trim());
					objObject.PostDate = DateTime.Parse(odrPCS[IV_MaterialIssueTable.POSTDATE_FLD].ToString().Trim());
					objObject.LocationID = int.Parse(odrPCS[IV_MaterialIssueTable.LOCATIONID_FLD].ToString().Trim());
					objObject.CCNID = int.Parse(odrPCS[IV_MaterialIssueTable.CCNID_FLD].ToString().Trim());
					objObject.TransNo = odrPCS[IV_MaterialIssueTable.TRANSNO_FLD].ToString().Trim();
					objObject.Comment = odrPCS[IV_MaterialIssueTable.COMMENT_FLD].ToString().Trim();
					objObject.ProductID = int.Parse(odrPCS[IV_MaterialIssueTable.PRODUCTID_FLD].ToString().Trim());
					objObject.UMID = int.Parse(odrPCS[IV_MaterialIssueTable.STOCKUMID_FLD].ToString().Trim());
					objObject.Lot = odrPCS[IV_MaterialIssueTable.LOT_FLD].ToString().Trim();
					objObject.Serial = odrPCS[IV_MaterialIssueTable.SERIAL_FLD].ToString().Trim();
					objObject.QAStatus = odrPCS[IV_MaterialIssueTable.QASTATUS_FLD].ToString().Trim();
					objObject.IssueType = int.Parse(odrPCS[IV_MaterialIssueTable.ISSUETYPE_FLD].ToString().Trim());
					objObject.IssueQuantity = Decimal.Parse(odrPCS[IV_MaterialIssueTable.ISSUEQUANTITY_FLD].ToString().Trim());
					
					if(!odrPCS[IV_MaterialIssueTable.BINID_FLD].Equals(DBNull.Value)
						&& !odrPCS[IV_MaterialIssueTable.BINID_FLD].ToString().Equals(string.Empty))
					{
						objObject.BinID = int.Parse(odrPCS[IV_MaterialIssueTable.BINID_FLD].ToString().Trim());
					}

					if(objObject.IssueType != (int)MaterialIssueType.SO_Issue)
					{
						objObject.WorkOrderMasterID = int.Parse(odrPCS[IV_MaterialIssueTable.WORKORDERMASTERID_FLD].ToString().Trim());
						objObject.WorkOrderDetailID = int.Parse(odrPCS[IV_MaterialIssueTable.WORKORDERDETAILID_FLD].ToString().Trim());
						objObject.SaleOrderMasterID = 0;
						objObject.SaleOrderDetailID = 0;
					}
					else
					{
						objObject.WorkOrderMasterID = 0;
						objObject.WorkOrderDetailID = 0;
						objObject.SaleOrderMasterID = int.Parse(odrPCS[IV_MaterialIssueTable.SALEORDERMASTERID_FLD].ToString().Trim());
						objObject.SaleOrderDetailID = int.Parse(odrPCS[IV_MaterialIssueTable.SALEORDERDETAILID_FLD].ToString().Trim());
					}
				}

				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		///    <summary>
		///       This method uses to add data to IV_MaterialIssue
		///    </summary>
		///    <Inputs>
		///        IV_MaterialIssueVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>		
	
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			IV_MaterialIssueVO objObject = (IV_MaterialIssueVO) pobjObjecVO;
			
			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			
			try 
			{				
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				string strSql = "UPDATE IV_MaterialIssue SET "
				+ IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.POSTDATE_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.BINID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.LOCATIONID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.CCNID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.TRANSNO_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.COMMENT_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.PRODUCTID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.STOCKUMID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.LOT_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.SERIAL_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.QASTATUS_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.ISSUETYPE_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.ISSUEQUANTITY_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.WORKORDERMASTERID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.WORKORDERDETAILID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.SALEORDERMASTERID_FLD + "=   ?" + ","
				+ IV_MaterialIssueTable.SALEORDERDETAILID_FLD + "=  ?"
				+ " WHERE " + IV_MaterialIssueTable.MASTERLOCATIONID_FLD + "= ?";
				
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD].Value = objObject.MaterialIssueMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.POSTDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[IV_MaterialIssueTable.POSTDATE_FLD].Value = objObject.PostDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.BINID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.BINID_FLD].Value = objObject.BinID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.LOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.LOCATIONID_FLD].Value = objObject.LocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.CCNID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.CCNID_FLD].Value = objObject.CCNID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.TRANSNO_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.TRANSNO_FLD].Value = objObject.TransNo;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.COMMENT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.COMMENT_FLD].Value = objObject.Comment;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.STOCKUMID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.STOCKUMID_FLD].Value = objObject.UMID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.LOT_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.LOT_FLD].Value = objObject.Lot;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SERIAL_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.SERIAL_FLD].Value = objObject.Serial;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.QASTATUS_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[IV_MaterialIssueTable.QASTATUS_FLD].Value = objObject.QAStatus;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.ISSUETYPE_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.ISSUETYPE_FLD].Value = objObject.IssueType;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.ISSUEQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_MaterialIssueTable.ISSUEQUANTITY_FLD].Value = objObject.IssueQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.WORKORDERMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERMASTERID_FLD].Value = objObject.WorkOrderMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.WORKORDERDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.WORKORDERDETAILID_FLD].Value = objObject.WorkOrderDetailID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SALEORDERMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERMASTERID_FLD].Value = objObject.SaleOrderMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.SALEORDERDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.SALEORDERDETAILID_FLD].Value = objObject.SaleOrderDetailID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MaterialIssueTable.MASTERLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MaterialIssueTable.MASTERLOCATIONID_FLD].Value = objObject.MasterLocationID;
				
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}

		///    <summary>
		///       This method uses to add data to IV_MaterialIssue
		///    </summary>
		///    <Inputs>
		///        IV_MaterialIssueVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();		

			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;

			try
			{
				string strSql = "SELECT "
				+ IV_MaterialIssueTable.MASTERLOCATIONID_FLD + ","
				+ IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD + ","
				+ IV_MaterialIssueTable.POSTDATE_FLD + ","
				+ IV_MaterialIssueTable.BINID_FLD + ","
				+ IV_MaterialIssueTable.LOCATIONID_FLD + ","
				+ IV_MaterialIssueTable.CCNID_FLD + ","
				+ IV_MaterialIssueTable.TRANSNO_FLD + ","
				+ IV_MaterialIssueTable.COMMENT_FLD + ","
				+ IV_MaterialIssueTable.PRODUCTID_FLD + ","
				+ IV_MaterialIssueTable.STOCKUMID_FLD + ","
				+ IV_MaterialIssueTable.LOT_FLD + ","
				+ IV_MaterialIssueTable.SERIAL_FLD + ","
				+ IV_MaterialIssueTable.QASTATUS_FLD + ","
				+ IV_MaterialIssueTable.ISSUETYPE_FLD + ","
				+ IV_MaterialIssueTable.ISSUEQUANTITY_FLD + ","
				+ IV_MaterialIssueTable.WORKORDERMASTERID_FLD + ","
				+ IV_MaterialIssueTable.WORKORDERDETAILID_FLD + ","
				+ IV_MaterialIssueTable.SALEORDERMASTERID_FLD + ","
				+ IV_MaterialIssueTable.SALEORDERDETAILID_FLD
				+ " FROM " + IV_MaterialIssueTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,IV_MaterialIssueTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
   				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		///    <summary>
		///       This method uses to add data to IV_MaterialIssue
		///    </summary>
		///    <Inputs>
		///        IV_MaterialIssueVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>
		
		public void UpdateDataSet(DataSet pdstData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";			
			OleDbConnection oconPCS = null;
			OleDbCommandBuilder odcbPCS ;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				string strSql = "SELECT "
				+ IV_MaterialIssueTable.MASTERLOCATIONID_FLD + ","
				+ IV_MaterialIssueTable.MATERIALISSUEMASTERID_FLD + ","
				+ IV_MaterialIssueTable.POSTDATE_FLD + ","
				+ IV_MaterialIssueTable.BINID_FLD + ","
				+ IV_MaterialIssueTable.LOCATIONID_FLD + ","
				+ IV_MaterialIssueTable.CCNID_FLD + ","
				+ IV_MaterialIssueTable.TRANSNO_FLD + ","
				+ IV_MaterialIssueTable.COMMENT_FLD + ","
				+ IV_MaterialIssueTable.PRODUCTID_FLD + ","
				+ IV_MaterialIssueTable.STOCKUMID_FLD + ","
				+ IV_MaterialIssueTable.LOT_FLD + ","
				+ IV_MaterialIssueTable.SERIAL_FLD + ","
				+ IV_MaterialIssueTable.QASTATUS_FLD + ","
				+ IV_MaterialIssueTable.ISSUETYPE_FLD + ","
				+ IV_MaterialIssueTable.ISSUEQUANTITY_FLD + ","
				+ IV_MaterialIssueTable.WORKORDERMASTERID_FLD + ","
				+ IV_MaterialIssueTable.WORKORDERDETAILID_FLD + ","
				+ IV_MaterialIssueTable.SALEORDERMASTERID_FLD + ","
				+ IV_MaterialIssueTable.SALEORDERDETAILID_FLD 
				+ " FROM " + IV_MaterialIssueTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pdstData.EnforceConstraints = false;
				odadPCS.Update(pdstData,IV_MaterialIssueTable.TABLE_NAME);
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}
			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	}
}